﻿using RuoVea.ExEnum;
using RuoVea.ExSugar.Attributes;
using RuoVea.ExSugar.Entity;
using SqlSugar;
using System.ComponentModel;

namespace RuoVea.OmiApi.Article.Entitys;

/// <summary>
/// 文章主表
/// </summary>
[SugarTable(nameof(ArtArticle), TableDescription = "文章主表")]
[Description("文章主表")]
[SugarIndex($"IX_{nameof(ArtArticle)}_{nameof(Title)}", nameof(Title), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(ArtArticle)}_{nameof(Status)}", nameof(Status), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(ArtArticle)}_{nameof(IsTop)}", nameof(IsTop), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(ArtArticle)}_{nameof(IsFeatured)}", nameof(IsFeatured), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(ArtArticle)}_{nameof(ViewCount)}", nameof(ViewCount), OrderByType.Desc)]
[SugarIndex($"IX_{nameof(ArtArticle)}_{nameof(CreateTime)}", nameof(CreateTime), OrderByType.Desc)]
public class ArtArticle : EntityBase
{
    /// <summary>
    /// 标题
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(Title), columnDescription :"标题", Length = 200)]
    public string Title { get; set; }

    /// <summary>
    /// 文章副标题
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(Subtitle), columnDescription :"文章副标题", Length = 500)]
    public string Subtitle { get; set; }

    /// <summary>
    /// 文章摘要
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(Summary), columnDescription :"文章摘要", Length = 1000)]
    public string Summary { get; set; }

    /// <summary>
    /// 封面图片URL
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(CoverImage), columnDescription :"封面图片URL", Length = 500)]
    public string CoverImage { get; set; }

    /// <summary>
    /// 状态：0-草稿，1-已发布，2-已下架
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(Status), columnDescription :"状态：0-草稿，1-已发布，2-已下架")]
    public int? Status { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    [ConfigSugarColumn(columnKey: nameof(Sort), columnDescription: "排序", IsNullable = true, DefaultValue = "10")]
    public int? Sort { get; set; } = 10;

    /// <summary>
    /// 阅读量
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(ViewCount), columnDescription :"阅读量", DefaultValue = "0")]
    public long? ViewCount { get; set; } = 0;

    /// <summary>
    /// 点赞数
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(LikeCount), columnDescription :"点赞数", DefaultValue = "0")]
    public int? LikeCount { get; set; } = 0;

    /// <summary>
    /// 评论数
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(CommentCount), columnDescription :"评论数", DefaultValue = "0")]
    public long? CommentCount { get; set; } = 0;

    /// <summary>
    /// 是否置顶
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(IsTop), columnDescription :"是否置顶")]
    public YesOrNot? IsTop { get; set; } = YesOrNot.N;

    /// <summary>
    /// 是否精选
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(IsFeatured), columnDescription :"是否精选")]
    public YesOrNot? IsFeatured { get; set; }= YesOrNot.N;

    /// <summary>
    /// 是否允许评论：0-否，1-是
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(IsCommentAllowed), columnDescription :"是否允许评论：0-否，1-是")]
    public YesOrNot? IsCommentAllowed { get; set; } = YesOrNot.Y;

    /// <summary>
    /// 文章内容
    /// </summary>
    [ConfigSugarColumn(columnKey:  nameof(Content), columnDescription :"文章内容", ColumnDataType = StaticConfig.CodeFirst_BigString)]
    public string Content { get; set; }

    /// <summary>
    /// 导航属性 - SEO（一对一）
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(Id))]
    [SugarColumn(IsIgnore = true)]
    public ArtSeo Seo { get; set; }

    /// <summary>
    /// 导航属性 - 点赞列表（一对多）
    /// </summary>
    [Navigate(NavigateType.OneToMany, nameof(ArtLike.ArticleId))]
    [SugarColumn(IsIgnore = true)]
    public List<ArtLike> Likes { get; set; }

    /// <summary>
    /// 导航属性 - 收藏列表（一对多）
    /// </summary>
    [Navigate(NavigateType.OneToMany, nameof(ArtFavorite.ArticleId))]
    [SugarColumn(IsIgnore = true)]
    public List<ArtFavorite> Favorites { get; set; }

    /// <summary>
    /// 导航属性 - 评论列表（一对多）
    /// </summary>
    [Navigate(NavigateType.OneToMany, nameof(ArtComment.ArticleId))]
    [SugarColumn(IsIgnore = true)]
    public List<ArtComment> Comments { get; set; }

    /// <summary>
    /// 导航属性 - 标签列表（多对多）
    /// </summary>
    [Navigate(typeof(ArtArticleTag), nameof(ArtArticleTag.ArticleId), nameof(ArtArticleTag.TagId))]
    [SugarColumn(IsIgnore = true)]
    public List<ArtTag> Tags { get; set; }

    /// <summary>
    /// 导航属性 - 分类列表（多对多）
    /// </summary>
    [Navigate(typeof(ArtCategoryArticle), nameof(ArtCategoryArticle.ArticleId), nameof(ArtCategoryArticle.CategoryId))]
    [SugarColumn(IsIgnore = true)]
    public List<ArtCategory> Categories { get; set; }

    /// <summary>
    /// 标签列表 
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public List<long> TagIds => Tags?.Select(x => x.Id)?.ToList();

    /// <summary>
    /// 分类列表 
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public List<long> CategorieIds => Categories?.Select(x => x.Id)?.ToList();
}
